﻿@{
    ViewBag.Title = "MembershipAnalysis";
}
@using MMS.UI.Extension;
@section headSection{
    <script src="/Scripts/echarts.js"></script>
    <script src="/Scripts/macarons.js"></script>
<div id="main" style="width:1160px; height:420px; margin: 0 auto;"></div>
    <script type="text/javascript">
        var mName = [];
        var yue = [];
        var cishu = [];
        function getdata(jsonText) {

            if (typeof (jsonText) == "string") {
                //msgObj = JSON.parse(jsonText);
                try {
                    //1.1将字符串 尝试转成 js 对象
                    //处理 数组字面量表示法的 json字符串：[{},{}]
                    jsonText = eval(jsonText);
                } catch (e) {
                    try {
                        //处理 对象字面量表示法的 json字符串:{}
                        jsonText = eval("(" + jsonText + ")");
                    } catch (e1) {
                        alert("格式错误：必须为json格式字符串~！");
                    }
                }
            }
          
            for (var i = 0; i < jsonText.length; i++) {
                mName[0] = jsonText[0].MName;
                yue[i] = jsonText[i].yue;
                cishu[i] = jsonText[i].cishu;
            }
        }
        getdata(@Html.Raw(ViewBag.data));
        var myChart = echarts.init(document.getElementById('main'), 'macarons');
        myChart.setOption({
            title: {
                text: mName[0]+'的忠诚度分析'
            },
            tooltip: {
                trigger: 'axis'
            },
            legend: {
                data: ['月购买次数']
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            toolbox: {
                feature: {
                    saveAsImage: {}
                }
            },
            xAxis: [{
                type: 'category',
                boundaryGap: false,
                data: yue
            }],
            yAxis: [{
                type: 'value'
            }],
            series: [
                {
                    name: '月购买次数',
                    type: 'line',
                    stack: '总量',
                    data: cishu
                }
            ]
        });         

    </script>
}

